<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\common\model;

use think\Model;

class Attribute extends Model
{
	/**
     * 获取属性
     * @param $label 标签
     * @access public
     */
	public function getAttrList($label)
	{
		return $this->where(['attr_label'=>$label,'is_del'=>0])->order('attr_sort',' asc')->select();
	}
	/**
     * 获取名称列表
     * @param $label 标签
     * @access public
     */
	public function getAttrNameList($label)
	{
		$data = array();
		$list = $this->where(['attr_label'=>$label,'is_del'=>0])->order('attr_sort',' asc')->select();
		foreach ($list as $key => $val) {
			$data[$val['attr_value']] = $val['attr_name'];
		}
		return $data;
	}
	/**
     * 获取属性
     * @param $arr_label 数组标签
     * @access public
     */
	public function getAttrData($arr_label)
	{
		$data = array();
		for ($i=0; $i < count($arr_label) ; $i++) {
			$data[$arr_label[$i]] = $this->where(['attr_label'=>$arr_label[$i],'is_del'=>0])->order('attr_sort',' asc')->select();
		}
		return $data;
	}
	/**
     * 获取属性名称
     * @param $label 标签
     * @param $value 值
     * @access public
     */
	public function getAttrName($label,$value)
	{
		$where = ['attr_label'=>$label,'attr_value'=>$value];
		return $this->where($where)->value('attr_name');
	}
}